package work2_28;

public class Computus {
    /**
     * 给定一个字符串，请你找出其中不含有重复字符的最长子串 的长度。
     * 输入： "abefge"
     * 输出： 5
     * abcabcd  --> 4
     * abaca    --> 3
     * aaaaa    --> 1
     * abbbbc   --> 2
     */

    public static void main(String[] args) {
        String str="abcddddefgadcx";
        subStr(str);
    }

    private static void subStr(String str){
        //子串的长度
        int max=1;
        //最大子串的输出
        String maxSub="";
        //for循环遍历整个数组
        for (int start = 0; start <str.length() ; start++) {
            //for循环找最大值
            out:for (int end = start+1; end <str.length()+1 ; end++) {
                //获取
                String substring=str.substring(start,end);
                //子串中不能重复出现
                for (int i = 0; i < substring.length(); i++) {
                    String replaceStr=substring.replace(substring.substring(i,i+1),"");
                    if(replaceStr.length()!=substring.length()-1){
                        continue out;
                    }
                }
                //一定不能重复
                if(substring.length()>max){
                    max=substring.length();
                    maxSub = substring;
                }
            }

        }
        System.out.println(maxSub);
        System.out.println(max);
    }
}

